package com.gjun.struts.action;

import java.io.PrintWriter;

import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;

import com.gjun.struts.resource.GjunSystemUserResourceIf;

public class SystemUserStateChangeAction {
	private String username;

	private String code;

	
	private GjunSystemUserResourceIf userResourceDAO;
	
	
	
	public GjunSystemUserResourceIf getUserResourceDAO() {
		return userResourceDAO;
	}

	public void setUserResourceDAO(GjunSystemUserResourceIf userResourceDAO) {
		this.userResourceDAO = userResourceDAO;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String execute() {
        try {
			boolean isUpdate = userResourceDAO.updateSystemUserState(username, code);
			if(isUpdate){
				HttpServletResponse response = ServletActionContext.getResponse();
				response.setContentType("text/html;charset=GBK");
				PrintWriter out = response.getWriter();
				out.println("<script type='text/javascript'>");
				out.println("  alert('激活完毕,确定进行登录')");
				out.println("  location.href='"+ServletActionContext.getRequest().getContextPath()+"/signin.jsp';");
				out.println("</script>");
				out.close();
				return null;
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		try{
			HttpServletResponse response = ServletActionContext.getResponse();
			response.setContentType("text/html;charset=GBK");
			PrintWriter out = response.getWriter();
			out.println("<script type='text/javascript'>");
			out.println("  alert('激活失败,请通知管理员')");
			out.println("  location.href='"+ServletActionContext.getRequest().getContextPath()+"/signin.jsp';");
			out.println("</script>");
			out.close();
			return null;
		}catch(Exception ex){
			ex.printStackTrace();
		}
		return null;
		
	}
}
